home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / workbench / term_4.8 / extras / source / term-source.lha / EmulationSpecial.c < prev    next >
C/C++ Source or Header  |  1997-03-11  |  6KB  |  443 lines

  1. /*
  2. **    EmulationSpecial.c
  3. **
  4. **    Special terminal emulation character handling
  5. **
  6. **    Copyright © 1990-1997 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "Global.h"
  14. #endif
  15.  
  16.     /* DoxON_xOFF():
  17.      *
  18.      *    This routine handles both xON and xOFF, it makes the emulation
  19.      *    swallow the character rather than printing it.
  20.      */
  21.  
  22. BOOL
  23. DoxON_xOFF()
  24. {
  25.     return(FALSE);
  26. }
  27.  
  28.     /* DoBackspace():
  29.      *
  30.      *    Special function: perform backspace.
  31.      */
  32.  
  33. BOOL
  34. DoBackspace()
  35. {
  36.     if(CursorX)
  37.     {
  38.         LONG DeltaX,MinX;
  39.  
  40.         CursorX--;
  41.  
  42.             /* What backspace mode are we in? */
  43.  
  44.         switch(Config->EmulationConfig->DestructiveBackspace)
  45.         {
  46.                 /* Do nothing */
  47.  
  48.             case 0:
  49.  
  50.                 RepositionCursor();
  51.                 break;
  52.  
  53.                 /* Shift the line to the left */
  54.  
  55.             case 2:
  56.  
  57.                 BackupRender();
  58.  
  59.                 RasterEraseCharacters(1);
  60.  
  61.                 if(FontScalingRequired)
  62.                 {
  63.                     if(CurrentCharWidth == SCALE_NORMAL)
  64.                     {
  65.                         DeltaX    = TextFontWidth * 2;
  66.                         MinX    = MUL_X(CursorX) * 2;
  67.                     }
  68.                     else
  69.                     {
  70.                         DeltaX    = TextFontWidth / 2;
  71.                         MinX    = MUL_X(CursorX) / 2;
  72.                     }
  73.                 }
  74.                 else
  75.                 {
  76.                     DeltaX    = TextFontWidth;
  77.                     MinX    = MUL_X(CursorX);
  78.                 }
  79.  
  80.                 ScrollLineEraseCharacters(1);
  81.  
  82.                 ScrollLineRaster(RPort,DeltaX,0,MinX,MUL_Y(CursorY),LastPixel,MUL_Y(CursorY + 1) - 1,FALSE);
  83.  
  84.                 BackupRender();
  85.  
  86.                 RepositionCursor();
  87.  
  88.                 RepairRaster();
  89.  
  90.                 break;
  91.  
  92.                 /* Clear the character below the cursor */
  93.  
  94.             default:
  95.  
  96.                 RepositionCursor();
  97.  
  98.                 ObtainSemaphore(&RasterSemaphore);
  99.  
  100.                 Raster[CursorY * RasterWidth + CursorX] = ' ';
  101.  
  102.                 ReleaseSemaphore(&RasterSemaphore);
  103.  
  104.                 BackupRender();
  105.  
  106.                 if(FontScalingRequired)
  107.                     PrintScaled(" ",1,CurrentFontScale);
  108.                 else
  109.                     Text(RPort," ",1);
  110.  
  111.                 BackupRender();
  112.  
  113.                 break;
  114.         }
  115.     }
  116.  
  117.     return(FALSE);
  118. }
  119.  
  120.     /* DoBeep():
  121.      *
  122.      *    The real interface to the beep routine.
  123.      */
  124.  
  125. BOOL
  126. DoBeep()
  127. {
  128.     BellSignal();
  129.  
  130.     return(FALSE);
  131. }
  132.  
  133.     /* DoLF():
  134.      *
  135.      *    Special function: perform line feed.
  136.      */
  137.  
  138. BOOL
  139. DoLF()
  140. {
  141.         /* This takes care of regular jump scrolling */
  142.  
  143.     if(CursorY == Bottom && Bottom > 0 && Config->EmulationConfig->MaxJump > 1)
  144.     {
  145.         LONG Scroll,TotalLines,OldBack = BackgroundPen;
  146.  
  147.         Scroll = Config->EmulationConfig->MaxJump;
  148.  
  149.             /* How tall is the current scroll region? */
  150.  
  151.         TotalLines = Bottom - Top + 1;
  152.  
  153.             /* Don't scroll more than the entire screenful */
  154.  
  155.         if(Scroll > TotalLines)
  156.             Scroll = TotalLines;
  157.  
  158.         if(OldBack)
  159.         {
  160.             BackgroundPen = 0;
  161.  
  162.             UpdatePens(RPort);
  163.         }
  164.  
  165.             /* Scroll the region... */
  166.  
  167.         ScrollRegion(Scroll);
  168.  
  169.             /* Reposition the cursor */
  170.  
  171.         if(CursorY > Scroll)
  172.             CursorY -= Scroll;
  173.         else
  174.             CursorY = 0;
  175.  
  176.         if(OldBack)
  177.         {
  178.             BackgroundPen = OldBack;
  179.  
  180.             UpdatePens(RPort);
  181.         }
  182.     }
  183.  
  184.     DownLine();
  185.  
  186.     RepositionCursor();
  187.  
  188.     return(FALSE);
  189. }
  190.  
  191.     /* DoShiftIn():
  192.      *
  193.      *    Special function: Shift into graphics mode
  194.      */
  195.  
  196. BOOL
  197. DoShiftIn()
  198. {
  199.     if(CharMode[1] == TABLE_GFX && GFX)
  200.         CurrentFont = GFX;
  201.  
  202.     if(CharMode[1] == TABLE_ASCII)
  203.         CurrentFont = TextFont;
  204.  
  205.     SetFont(RPort,CurrentFont);
  206.  
  207.     ConOutputUpdate();
  208.  
  209.     Charset = 1;
  210.  
  211.     return(FALSE);
  212. }
  213.  
  214.     /* DoShiftOut():
  215.      *
  216.      *    Special function: Shift out of graphics mode
  217.      */
  218.  
  219. BOOL
  220. DoShiftOut()
  221. {
  222.     if(CharMode[0] == TABLE_GFX && GFX)
  223.         CurrentFont = GFX;
  224.  
  225.     if(CharMode[0] == TABLE_ASCII)
  226.         CurrentFont = TextFont;
  227.  
  228.     SetFont(RPort,CurrentFont);
  229.  
  230.     ConOutputUpdate();
  231.  
  232.     Charset = 0;
  233.  
  234.     return(FALSE);
  235. }
  236.  
  237.     /* DoCR_LF():
  238.      *
  239.      *    Special function: perform carriage return and line feed.
  240.      */
  241.  
  242. BOOL
  243. DoCR_LF()
  244. {
  245.     CursorX = 0;
  246.  
  247.     DownLine();
  248.  
  249.     RepositionCursor();
  250.  
  251.     return(FALSE);
  252. }
  253.  
  254.     /* DoFF():
  255.      *
  256.      *    Special function: perform form feed.
  257.      */
  258.  
  259. BOOL
  260. DoFF()
  261. {
  262.     if(Config->EmulationConfig->NewLineMode)
  263.     {
  264.         CursorX = 0;
  265.  
  266.         DoCR_LF();
  267.     }
  268.     else
  269.     {
  270.         EraseScreen("2");
  271.  
  272.         CursorX = CursorY = 0;
  273.  
  274.         RepositionCursor();
  275.  
  276.         ConFontScaleUpdate();
  277.     }
  278.  
  279.     return(FALSE);
  280. }
  281.  
  282.     /* DoLF_FF_VT():
  283.      *
  284.      *    Special function: handle line feed, form feed and vertical
  285.      *    tab.
  286.      */
  287.  
  288. BOOL
  289. DoLF_FF_VT()
  290. {
  291.     if(Config->EmulationConfig->NewLineMode)
  292.         DoCR_LF();
  293.     else
  294.         DoLF();
  295.  
  296.     return(FALSE);
  297. }
  298.  
  299.     /* DoCR():
  300.      *
  301.      *    Special function: handle carriage return.
  302.      */
  303.  
  304. BOOL
  305. DoCR()
  306. {
  307.     if(Config->EmulationConfig->NewLineMode)
  308.         DoCR_LF();
  309.     else
  310.     {
  311.         CursorX = 0;
  312.  
  313.         RepositionCursor();
  314.     }
  315.  
  316.     return(FALSE);
  317. }
  318.  
  319.     /* DoTab():
  320.      *
  321.      *    Special function: handle tab, move cursor to next
  322.      *    tab stop.
  323.      */
  324.  
  325. BOOL
  326. DoTab()
  327. {
  328.     LONG Column;
  329.  
  330.     if(RasterAttr[CursorY] == SCALE_ATTR_NORMAL)
  331.         Column = LastColumn;
  332.     else
  333.         Column = ((LastColumn + 1) / 2) - 1;
  334.  
  335.     if(Config->EmulationConfig->LineWrap)
  336.     {
  337.         if(CursorX >= LastColumn)
  338.         {
  339.             CursorX = 0;
  340.  
  341.             DownLine();
  342.         }
  343.         else
  344.         {
  345.             while(CursorX < Column)
  346.             {
  347.                 CursorX++;
  348.  
  349.                 if(TabStops[CursorX])
  350.                     break;
  351.             }
  352.         }
  353.     }
  354.     else
  355.     {
  356.         while(CursorX < Column)
  357.         {
  358.             CursorX++;
  359.  
  360.             if(TabStops[CursorX])
  361.                 break;
  362.         }
  363.     }
  364.  
  365.     RepositionCursor();
  366.  
  367.     return(FALSE);
  368. }
  369.  
  370.     /* DoEnq():
  371.      *
  372.      *    Special function: send answerback message.
  373.      */
  374.  
  375. BOOL
  376. DoEnq()
  377. {
  378.     if(Config->EmulationConfig->AnswerBack[0])
  379.         SerialCommand(Config->EmulationConfig->AnswerBack);
  380.  
  381.     return(FALSE);
  382. }
  383.  
  384.     /* DoEsc():
  385.      *
  386.      *    Start new control sequence.
  387.      */
  388.  
  389. BOOL
  390. DoEsc()
  391. {
  392.     if(Config->TerminalConfig->EmulationMode == EMULATION_TTY)
  393.         (* ConDump)("^",1);
  394.  
  395.     return(TRUE);
  396. }
  397.  
  398.     /* DoCsi():
  399.      *
  400.      *    Start new control sequence.
  401.      */
  402.  
  403. BOOL
  404. DoCsi()
  405. {
  406.     if(Config->TerminalConfig->EmulationMode == EMULATION_TTY)
  407.         (* ConDump)("^[",2);
  408.  
  409.     return(ParseCode('['));
  410. }
  411.  
  412.     /* DoNewEsc(LONG Char):
  413.      *
  414.      *    Start new control sequence.
  415.      */
  416.  
  417. BOOL
  418. DoNewEsc(LONG UnusedChar)
  419. {
  420.     if(Config->TerminalConfig->EmulationMode == EMULATION_TTY)
  421.         (* ConDump)("^",1);
  422.  
  423.     DoCancel();
  424.  
  425.     return(TRUE);
  426. }
  427.  
  428.     /* DoNewCsi(LONG Char):
  429.      *
  430.      *    Start new control sequence.
  431.      */
  432.  
  433. BOOL
  434. DoNewCsi(LONG UnusedChar)
  435. {
  436.     if(Config->TerminalConfig->EmulationMode == EMULATION_TTY)
  437.         (* ConDump)("^[",2);
  438.  
  439.     DoCancel();
  440.  
  441.     return(ParseCode('['));
  442. }
  443.